package work.droit.gui;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import work.util.data.io.ManipFile;
import work.util.editor.EditorLauncher;

import com.hexidec.ekit.Ekit;

public class EkiEditor
{
	public static void launchEditor(final boolean edition,
			final String fileName, final String docName, final String docType)
	{
		Runnable run = new Runnable()
		{
			@Override
			public void run()
			{
				String sDocument = ApiController.pathDocument + fileName
						+ EditorLauncher.FILE_EXTENSION;
				File file = new File(sDocument);
				try
				{
					if (!file.exists())
					{
						file.createNewFile();
						// on ajoute les balises html
						ManipFile.saveContent(sDocument, "<html></html>");
					}
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
				String sStyleSheet = null;
				String sRawDocument = null;
				URL urlStyleSheet = null;
				boolean includeToolBar = edition;
				boolean showViewSource = false;
				boolean showMenuIcons = edition;
				boolean editModeExclusive = edition;
				String sLanguage = null;
				String sCountry = null;
				boolean base64 = false;
				boolean debugMode = false;
				boolean useSpellChecker = false;
				boolean multiBar = edition;
				boolean menuBar = edition;
				boolean enterBreak = true;
				boolean editable = edition;
				Ekit ekit = new Ekit(sDocument, sStyleSheet, sRawDocument,
						urlStyleSheet, includeToolBar, showViewSource,
						showMenuIcons, editModeExclusive, sLanguage, sCountry,
						base64, debugMode, useSpellChecker, multiBar, menuBar,
						enterBreak, editable);
				ekit.setTitle(docType + " - " + docName);
			}
		};

		Thread thread = new Thread(run);

		thread.start();
		// tant que le thread est en vie...
		while (thread.isAlive())
		{
			try
			{
				Thread.sleep(2600);
			}
			catch (InterruptedException ex)
			{
			}
		}
	}
}
